package com.acme.iolab.filecopy.nio;

import com.acme.iolab.filecopy.FileCopyHelper;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

public class NIOFileCopyHelper extends FileCopyHelper {

    @Override
    public void copyFile(File source, File target) throws IOException {
        try (FileChannel src = new FileInputStream(source).getChannel();
             FileChannel trg = new FileOutputStream(target).getChannel()) {
            trg.transferFrom(src, 0, src.size());
        }
    }
}
